package com.app.android.coliy.adapter;

import androidx.annotation.NonNull;
import com.app.android.coliy.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.feasycom.bean.BluetoothDeviceWrapper;

public class DeviceAdapter extends BaseQuickAdapter<BluetoothDeviceWrapper, BaseViewHolder> {

    public DeviceAdapter() {
        super(R.layout.search_device_info);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, BluetoothDeviceWrapper item) {

        if (item != null) {

            String deviceName = item.getName();
            String address = item.getAddress();
            if (deviceName != null && deviceName.length() > 0) {
                //设备名长度限制，最大30
                if (deviceName.length() >= 30) {
                    deviceName = deviceName.substring(0, 30);
                }
            } else {
                deviceName = address;
            }


            if (address != null && address.length() > 0) {
                address = "(" + address + ")";
            } else {
                address = "Unknown address";
            }


            helper.setText(R.id.tv_name, deviceName)
                .setText(R.id.tv_addr, address);
            helper.setText(R.id.tv_rssi,item.getRssi()+"");

        }
    }
}
